// let realmName = "http://172.16.0.127:8088";
// let realmName = "http://10.19.0.40:8088";
// let realmName = "http://172.16.0.110:80";
let realmName = "http://39.105.85.75:61500"; //测试环境 api_test
// socket.js 不与其使用
// let realmName = 'https://hxc.ctvig.com';
import { login } from '@/http';
const http = obj => {
	return uni.request({
		url: realmName + obj.urls,
		method: obj.method,
		data: obj.data,
		header: obj.header,
		success: async res => {
			if (res.data.code == 200) {
				if (obj.callBack) {
					obj.callBack(res);
				}
			} else {
				if(Number(res.data.code) == 401){ //如果是401那么重新获取权限
					await login()
				}
				uni.showModal({
					title: `提示`,
					content: `${res.data.msg}`,
					showCancel: false
				});
			}
			uni.hideLoading();
		},
		fail: res => {
			uni.hideLoading();
		}
	})
}
const getToken = () => {
	return uni.getStorageSync('Authorization');
}
export default {
	realmName,
	reqForm(method, urls, data) {
		return new Promise((relove, reject) => {
			http({
				urls,
				method,
				data,
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'openId': uni.getStorageSync('openid'),
					'Authorization': getToken()
				},
				callBack: res => {
					relove(res)
				}
			})
		})
	},
	reqJson(method, urls, data) {
		return new Promise((relove, reject) => {
			http({
				urls,
				method,
				data,
				header: {
					'content-type': 'application/json',
					'openId': uni.getStorageSync('openid'),
					'Authorization': getToken()
				},
				callBack: res => {
					relove(res)
				}
			})
		})
	},
}
